<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="admin.*"%>
<%@ page import="goods.*"%>
<fmt:requestEncoding value="utf-8" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<c:choose>
	<c:when test="${sessionScope.SESSION_MB_NO == null }">
		<script type="text/javascript">
		<!--
		alert("로그인후 사용 하실수 있습니다..");
		history.back(-1);
		//-->
		</script>
	</c:when>
</c:choose>

<%@ include file="/Dmyna/head.jsp" %>
<c:set var="WEB_ROOT" value="/Dmyna" />

<script type="text/javascript">
<!--
function validate(form){
	alert("상품 주문을 완료 합니다.");

}
//-->
</script>

<%
	MemberWriting mbInfo = null;
	String mb_no = (String)session.getAttribute("SESSION_MB_NO");

	MemberWritingManager mbManager = MemberWritingManager.getInstance();
	mbInfo = mbManager.select(Integer.parseInt(mb_no));
%>

<c:set var="mbInfo" value="<%=mbInfo%>" />

<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div
					style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;"
					align="center">::&nbsp;&nbsp;상품 주문 신청&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>

<form action="/orderInsert.do" method="post" name="order_from" onSubmit="return validate(this)">
<table width="900" border="1" align="center" bordercolor="#f0f0f0">
<tr>
	<td colspan="4">[배송지 및 주문자 정보]</td>
</tr>
<tr>
	<td width="20%" bgcolor="#DFDFDF" >수취인</td>
	<td width="80%"><input type="text" size="75" name="OI_NAME" value="${mbInfo.mb_name }"/></td>
</tr>
<tr>
	<td bgcolor="#DFDFDF">주소</td>
	<td><input type="text" size="75" name="OI_ADDR" value="${mbInfo.mb_addr1 } ${mbInfo.mb_addr2 }"/></td>
</tr>
</table>

<br /><br />
<%
String listGsCode = request.getParameter("LIST_GS_CODE");
String listGsCount = request.getParameter("LIST_GS_COUNT");
String listGsColor = request.getParameter("LIST_GS_COLOR");
String listGsSize = request.getParameter("LIST_GS_SIZE");
String tokTmpCode = "";
String tokTmpCount = "";
String tokTmpColor = "";
String tokTmpSize = "";

String listGsPrice = "";

StringTokenizer tokGsCode = new StringTokenizer(listGsCode, "|");
StringTokenizer tokGsCount = new StringTokenizer(listGsCount, "|");
StringTokenizer tokGsColor = new StringTokenizer(listGsColor, "|");
StringTokenizer tokGsSize = new StringTokenizer(listGsSize, "|");
%>

<table width="900" border="" align="center" bordercolor="#f0f0f0">
<tr>
	<td colspan="6">[주문 상품 리스트]</td>
</tr>

<tr align="center" bgcolor="#DFDFDF">
	<td width="100">이미지</td>
	<td>상품명</td>
	<td width="100">수량</td>
	<td width="100">판매가</td>
</tr>
<%
GoodsManager orderGoodsManager = GoodsManager.getInstance();
GoodsItem orderGoodsItem = null;
int ordPrice = 0;
int ordTotPrice = 0;

int loopCnt = 0;
while (tokGsCode.hasMoreTokens()){
	tokTmpCode = tokGsCode.nextToken();
	tokTmpCount = tokGsCount.nextToken();
	tokTmpColor = tokGsColor.nextToken();
	tokTmpSize = tokGsSize.nextToken();
	
	orderGoodsItem = orderGoodsManager.select2(tokTmpCode);
	
	ordPrice = ordPrice + orderGoodsItem.getGs_sale_price() * Integer.parseInt(tokTmpCount);
	if(loopCnt == 0) listGsPrice = listGsPrice + String.valueOf(orderGoodsItem.getGs_sale_price());
	else listGsPrice = listGsPrice + "|" + String.valueOf(orderGoodsItem.getGs_sale_price());
	loopCnt++;
%>
<c:set var="orderGoodsItem" value="<%=orderGoodsItem%>" />
<tr align="center">
	<td width="100"><img src="${WEB_ROOT }/goods/upload/small.${orderGoodsItem.gs_img }" width="100" height="100" /></td>
	<td>${orderGoodsItem.gs_name } (색상 : <%=tokTmpColor %> / 사이즈 : <%=tokTmpSize %>)</td>
	<td width="100"><%=tokTmpCount %></td>
	<td width="100"><fmt:formatNumber value="${orderGoodsItem.gs_sale_price }" type="number"/></td>
</tr>

<%
}
ordTotPrice = ordPrice + 2500;
%>
</table>

<br /><br />

<input type="hidden" name="LIST_GS_CODE" value="<%=listGsCode %>" />
<input type="hidden" name="LIST_GS_COUNT" value="<%=listGsCount %>" />
<input type="hidden" name="LIST_GS_PRICE" value="<%=listGsPrice %>" />

<input type="hidden" name="LIST_GS_COLOR" value="<%=listGsColor %>" />
<input type="hidden" name="LIST_GS_SIZE" value="<%=listGsSize %>" />
<input type="hidden" name="OI_PRICE" value="<%=ordPrice %>" />
<input type="hidden" name="OI_TOTAL_PRICE" value="<%=ordTotPrice %>" />


<table width="900" border="1" align="center" bordercolor="#f0f0f0">
<tr>
	<td align="center" colspan="2">상품구매금액 : <fmt:formatNumber value="<%=ordPrice %>" type="number"/>원 + 배송비 : 2,500원 = [총구매액] : <fmt:formatNumber value="<%=ordTotPrice %>" type="number"/>원</td>
</tr>
<tr>
	<td height="25" align="left"><input type="button" value="주문  취소"  onclick="javascript:history.back(-1);"/></td>
	<td height="25" align="right"><input type="submit" value="주문 완료" /></td>
</tr>
</table>
</form>

<br /><br />
<%@ include file="/Dmyna/tail.jsp" %>
